# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=shelly
pkgname=haskell-shelly
pkgver=1.10.0.1
pkgrel=6
pkgdesc="Shell-like (systems) programming in Haskell"
url="https://github.com/gregwebs/Shelly.hs"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-unix-compat' 'haskell-monad-control' 'haskell-lifted-base'
         'haskell-lifted-async' 'haskell-enclosed-exceptions'
         'haskell-async' 'haskell-transformers-base')
makedepends=('ghc' 'uusi' 'haskell-hunit' 'haskell-hspec' 'haskell-hspec-contrib')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('8e90587a1f8580b9dade4a72c59d54962a1bb52eb468f059378c02f3fbd94730fe66d1e960afeccce2748e1ffe49b06a49bf90d53c9d7f8ee3b7173099c45796')

prepare() {
    cd $_hkgname-$pkgver
    uusi -u unix-compat $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -f-lifted -f-build-examples
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
